$(function(){
	(function(){
		function IsPC(){    
			 var userAgentInfo = navigator.userAgent;  
			 var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");    
			 var flag = true;    
			 for (var v = 0; v < Agents.length; v++) {    
				 if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }    
			 }    
			 return flag;    
		  } 
		 if($(".video_play").length>0){
			
		 $.ajax({
			url: _V.url,
			data:{id:_V.id},
			type: "POST",
			dataType: "json",
			success: function(data) {
				  var _Video=data;
				  $(".video_play").each(function(index, element){
					  var o=$(this);
					  var ad_play=o.find("#ad_play");
					  var ad_time=o.find(".ad_time");
					  var details=o.find(".details");
					  var imgAd=o.find(".img");
					  var controlbar=ad_play.find(".prism-controlbar");
					  var title=o.find(".title");
					  // 初始化播放器
					var player = new prismplayer({
						id: "ad_play", // 容器id
						source: _Video.ad,// 视频地址
						endAd: _Video.endAd,// 视频地址
						video_url:_Video.video_url,
						autoplay: false,    //自动播放：否
						width: "100%",       // 播放器宽度
						height: IsPC()?"100%":"10.6rem", // 播放器高度
						//showBarTime: 3000000,
						cover:_Video.cover,
						isLive:_Video.isLive,  //是否为直播
						ad_time:_Video.ad.length>0?_Video.ad_duration:0,
						endAdTime:_Video.endAd.length>0?_Video.endAdTime:0,
						playTime:_Video.playTime,
						showBuffer:true,
						autoplay: false,
						vid : _Video.vid,
						accId : _Video.accId,
						accSecret: _Video.accSecret,
						apiKey :_Video.apiKey,
						adId:_Video.adId,
						endAdId:_Video.endAdId,
						// liveLogo:_Video.liveLogo,
						playsinline:true,
						adSend:"/adcommon/click.json?id=4"     //广告打点接口
					});
					var curr = 0;  
					var timer=null
					var timerr=null
					var video =ad_play.find("video")[0];
					var html='<div class="ad_time">广告还剩<b>'+_Video.ad_duration+'</b>s</div><a class="details">了解详情</a><a class="img"><img src='+_Video.ad_img+'></a><div class="title">'+_Video.title+'</div>';

					var setTime=function(){
						clearInterval(timer)
						timer=setInterval(function(){
							 if(_Video.adlink.lenght>0){
								 ad_play.find('video').unbind("click").bind("click",function(){
									window.open(_Video.adlink); 
								 })
							 }
							 $(ad_time.selector).find("b").text($(ad_time.selector).find("b").text()-1);
							 if(parseInt($(ad_time.selector).find("b").text())<=0){
									$(controlbar.selector).css({"opacity":1})
									$(ad_time.selector).hide();
									if(_Video.isLive){
									  $("<div class=\"live\"></div>").appendTo(o);
									//   if(_Video.liveLogo){
									// 	 $(".live").css({"background": "url("+_Video.liveLogo+") 0px -390px no-repeat"})
									//   }
									}
									$(details.selector).hide();
									ad_play.find('video').unbind("click")
									// play()
									clearInterval(timer)
								}
						},1000)
					}
					function ready(){
						if($(ad_time.selector).length>0){
							setTime()   
						}
					}
					$(html).appendTo(o);
					player.on("waiting", function() {
						 clearInterval(timer)
					});
					player.on("canplaythrough", function() {
						if(parseInt($(ad_time.selector).find("b").text())>0){
						 setTime()
					   }
				   });
					//视频暂停
					player.on("pause", function() {
						//$(imgAd.selector).show()
						$(".prism-big-play-btn").show()
						 clearInterval(timer)
					});
					//视频播放完毕
					player.on("ended", function() {
						//$(imgAd.selector).hide()
						$(".prism-big-play-btn").hide()
						
					});
					//视频播放
					if(_Video.ad.length){
						  $(controlbar.selector).css({"opacity":0});
					 }
					 else
					 {
						 $(controlbar.selector).css({"opacity":1});
					 }
					$(ad_time.selector).find("b").text(_Video.count);
					$(details.selector).attr("href",_Video.adlink)
					$(imgAd.selector).attr("href",_Video.adlink);
					player.on("ready", function() {
							  var len=player.getDuration()
								if(len>0){
								// $(imgAd.selector).hide()
								 if(_Video.ad.length>0){
									 $(ad_time.selector).show()
									 $(details.selector).show()
								 }
								 ready()
						 }
					});
					//视频播放完毕
					player.on("play", function() {
						//$(imgAd.selector).hide()
						ready()
						$(".prism-cover").hide()
					});
					$(".prism-player video").attr("webkit-playsinline","")
		            $(".prism-big-play-btn").css({"left":($(window).width()-33)/2,"bottom":($(".prism-cover").height()-40)/2});
				});
			},
			error: function(er) {
				console.log(er)
			}
		});
	  }
	})()
	
})